package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.SelfTeamChildEntity;
import com.sgb.kjwl.model.entity.self.SelfTeamEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class SelfTeamAdapter extends BaseRecycleAdapter<SelfTeamEntity> {

    private TextView delView;
    private TextView timeView;
    private TextView typeView;
    private ItemCallBack itemCallBack;

    public SelfTeamAdapter(Context context, List<SelfTeamEntity> datas) {
        super(context, R.layout.item_self_team, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        delView = holder.getItem().findViewById(R.id.del_view);
        timeView = holder.getItem().findViewById(R.id.time_view);
        typeView = holder.getItem().findViewById(R.id.tv_team_type);
        delView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.del(entity.getId());
                }
            }
        });
        try {
            timeView.setText(DateUtils.timestampTo13Date3(Long.parseLong(entity.getCreateTime())));
        } catch (Exception e) {
            timeView.setText(entity.getCreateTime());
        }
        List<SelfTeamChildEntity> list = entity.getTeamChildEntityList();
        if (list != null) {
            StringBuffer sb = new StringBuffer("");
            for (SelfTeamChildEntity entity1 : list) {
                sb.append(entity1.getFirstCategoryName() + "、");
            }
            String type = sb.substring(0, sb.length() - 1);
            typeView.setText(type);
        }

    }

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    public interface ItemCallBack {
        void del(String id);
    }
}
